import SwiftUI

/*
 * 树示例
 */
class TreeExample: FCUIView{
    /*
    * 触摸开始方法
    * view:视图
    * firstTouch:是否第一次触摸
    * firstPoint:第一次触摸的坐标
     * secondTouch:是否第二次触摸
    * secondPoint:第二次触摸的坐标
    */
    override func onTouchBegin(view:FCView, firstTouch:Bool, firstPoint:FCPoint, secondTouch:Bool, secondPoint:FCPoint) {
        super.onTouchBegin(view:view, firstTouch:firstTouch,  firstPoint:firstPoint, secondTouch:secondTouch, secondPoint:secondPoint)
    }

    /*
    * 触摸移动方法
    * view:视图
    * firstTouch:是否第一次触摸
    * firstPoint:第一次触摸的坐标
    * secondTouch:是否第二次触摸
    * secondPoint:第二次触摸的坐标
    */
    override func onTouchMove(view:FCView, firstTouch:Bool, firstPoint:FCPoint, secondTouch:Bool, secondPoint:FCPoint) {
        super.onTouchMove(view:view, firstTouch:firstTouch, firstPoint:firstPoint, secondTouch:secondTouch, secondPoint:secondPoint)
    }

    /*
    * 触摸结束方法
    * view:视图
    * firstTouch:是否第一次触摸
    * firstPoint:第一次触摸的坐标
    * secondTouch:是否第二次触摸
    * secondPoint:第二次触摸的坐标
    */
    override func onTouchEnd(view:FCView, firstTouch:Bool, firstPoint:FCPoint, secondTouch:Bool, secondPoint:FCPoint) {
        super.onTouchEnd(view:view, firstTouch:firstTouch, firstPoint:firstPoint, secondTouch:secondTouch, secondPoint:secondPoint)
    }

    /*
    * 点击方法
    * view:视图
    * firstTouch:是否第一次触摸
    * firstPoint:第一次触摸的坐标
    * secondTouch:是否第二次触摸
    * secondPoint:第二次触摸的坐标
    * clcks:点击次数
    */
    override func onClick(view:FCView, firstTouch:Bool, firstPoint:FCPoint, secondTouch:Bool, secondPoint:FCPoint, clicks:Int) {
        super.onClick(view:view, firstTouch:firstTouch, firstPoint:firstPoint, secondTouch:secondTouch, secondPoint:secondPoint, clicks: clicks)
    }

    /*
    * 重绘背景的实现方法
    * view:视图
    * paint:绘图对象
    * clipRect:裁剪区域
    */
    override func onPaint(view:FCView, paint:FCPaint, clipRect:FCRect) {
        super.onPaint(view:view, paint:paint, clipRect:clipRect)
    }

    /*
    * 重绘边框的实现方法
    * view:视图
    * paint:绘图对象
    * clipRect:裁剪区域
    */
    override func onPaintBorder(view:FCView, paint:FCPaint, clipRect:FCRect) {
        super.onPaintBorder(view:view, paint:paint, clipRect:clipRect)
    }
    
    /*
     * 初始化布局
     */
    override func onLoad(){
        let isInit = super.m_isInit
        super.onLoad()
        if !isInit{
            m_paint.defaultUIStyle = "light"
            let width = Double(self.frame.size.width), height = Double(self.frame.size.height)
            renderFaceCat(name:"treeexample", paint: m_paint, size: FCSize(cx:width, cy:height))
            let tree = findViewByName(name:"Tree", views:m_paint.views) as! FCTree
            tree.headerHeight = 0
            tree.showCheckBox = true
            let column = FCTreeColumn()
            column.width = 500
            tree.columns.append(column)

            let noneNode = FCTreeNode()
            noneNode.isNotEmpty = false
            
            let rootNode = FCTreeNode()
            rootNode.value = "证监会行业类"
            appendTreeNode(tree:tree, node:rootNode, parentNode:noneNode)

            let node1 = FCTreeNode()
            node1.value = "农、林、牧、渔业"
            appendTreeNode(tree:tree, node:node1, parentNode: rootNode)

            var strs1 = [String]()
            strs1.append("农业")
            strs1.append("林业")
            strs1.append("畜牧业")
            strs1.append("渔业")
            strs1.append("农、林、牧、渔服务业")
            for i in 0...strs1.count - 1{
                let subNode1 = FCTreeNode()
                subNode1.value = strs1[i]
                appendTreeNode(tree:tree, node:subNode1, parentNode:node1)
            }

            let node2 = FCTreeNode()
            node2.value = "采矿业"
            appendTreeNode(tree:tree, node:node2, parentNode:rootNode)

            var strs2 = [String]()
            strs2.append("煤炭开采和洗选业")
            strs2.append("石油和天然气开采业")
            strs2.append("黑色金属矿采选业")
            strs2.append("有色金属矿采选业")
            strs2.append("非金属矿采选业")
            strs2.append("开采辅助活动")
            for i in 0...strs2.count - 1{
                let subNode2 = FCTreeNode()
                subNode2.value = strs2[i]
                appendTreeNode(tree:tree, node:subNode2, parentNode:node2)
            }

            let node3 = FCTreeNode()
            node3.value = "制造业"
            appendTreeNode(tree:tree, node:node3, parentNode:rootNode)

            var strs3 = [String]()
            strs3.append("农副食品加工业")
            strs3.append("食品制造业")
            strs3.append("酒、饮料和精制茶制造业")
            strs3.append("纺织业")
            strs3.append("纺织服装、服饰业")
            strs3.append("皮革、毛皮、羽毛及其制品和制鞋业")
            strs3.append("木材加工和木、竹、藤、棕、草制品业")
            strs3.append("家具制造业")
            strs3.append("造纸和纸制品业")
            strs3.append("印刷和记录媒介复制业")
            strs3.append("文教、工美、体育和娱乐用品制造业")
            strs3.append("石油加工、炼焦和核燃料加工业")
            strs3.append("化学原料及化学制品制造业")
            strs3.append("医药制造业")
            strs3.append("化学纤维制造业")
            strs3.append("橡胶和塑料制品业")
            strs3.append("非金属矿物制品业")
            strs3.append("黑色金属冶炼和压延加工业")
            strs3.append("有色金属冶炼和压延加工业")
            strs3.append("金属制品业")
            strs3.append("通用设备制造业")
            strs3.append("专用设备制造业")
            strs3.append("汽车制造业")
            strs3.append("铁路、船舶、航空航天和其他运输设备制造业")
            strs3.append("电气机械和器材制造业")
            strs3.append("计算机、通信和其他电子设备制造业")
            strs3.append("仪器仪表制造业")
            strs3.append("其他制造业")
            strs3.append("废弃资源综合利用业")
            for i in 0...strs3.count - 1{
                let subNode3 = FCTreeNode()
                subNode3.value = strs3[i]
                appendTreeNode(tree:tree, node:subNode3, parentNode:node3)
            }
            invalidate(paint:m_paint)
        }
    }
}
